﻿using System;
using Rhino.Mocks;

namespace Mockery.Core
{

    /// <summary>
    /// Manages the repository state event dispatching based on the current running state
    /// </summary>
    public class RepositoryStateHandler : IRepositoryStateHandler
    {
        private readonly IMockeryStateEvents _mockeryStateEvents;

        /// <summary>
        /// standard ctor
        /// </summary>
        /// <param name="mockeryStateEvents">set of registered state events</param>
        public RepositoryStateHandler(IMockeryStateEvents mockeryStateEvents)
        {
            _mockeryStateEvents = mockeryStateEvents;
        }

        /// <summary>
        /// State dispatch method that fires on a state change
        /// </summary>
        /// <param name="mockeryState">current mockery state being set</param>
        public void SetState(MockeryState mockeryState)
        {
           switch( mockeryState)
           {
               case MockeryState.Arrange:
                   _mockeryStateEvents.OnFirstArrange();
                   break;
                   
               case MockeryState.Act:
                   _mockeryStateEvents.OnFirstAct();
                   break;

               case MockeryState.Assert:
                   _mockeryStateEvents.OnFirstAssert();
                   break;

               default:
                   // nothing to do in this case
                   break;
           }
        }
    }
}
